package com.genius.smsdao.studentmanage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.genius.smsbase.Domain.BaseEntity;
import com.genius.smsdao.actionmanage.domain.Action;
import com.genius.smsdao.attendancemanage.domain.Attendance;
import com.genius.smsdao.coursemanage.domain.Course;
import com.genius.smsdao.dormitorymanage.domain.Dormitory;
import com.genius.smsdao.scoremanage.domain.Score;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Entity:Student 学生实体类
 * 对应数据库表名：student
 * @author：Mie
 */
@Entity
@Table(name = "student")
public class Student extends BaseEntity<Long> {

    @Column
    private String number;
    @Column
    private String sex;
    @Column
    private String name;
    @Column
    private String password;
    @Column
    private String telephone;

    //学生到年级多对一关系
    @JsonIgnoreProperties(value = "studentList")
    @ManyToOne(targetEntity = Grade.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "grade_id",referencedColumnName = "id")
    private Grade grade;

    //学生到宿舍多对一关系
    @JsonIgnoreProperties(value = "studentList")
    @ManyToOne(targetEntity = Dormitory.class,cascade = {CascadeType.REFRESH},fetch = FetchType.LAZY)
    @JoinColumn(name = "dormitory_id",referencedColumnName = "id")
    private Dormitory dormitory;

    //学生到课程多对多关系，课程被选
    @JsonIgnoreProperties(value = "studentList")
    @ManyToMany(targetEntity = Course.class)
    @JoinTable(name = "select_course",
            joinColumns = @JoinColumn(name = "student_id",referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "course_id",referencedColumnName = "id"))
    private List<Course> courseList;

    //学生到成绩一对多关系
    @JsonIgnoreProperties(value = "student")
    @OneToMany(mappedBy = "student",cascade = {CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.LAZY)
    private List<Score> scoreList;

    //学生到二课活动多对多关系，二课被选
    @JsonIgnoreProperties(value = "studentList")
    @ManyToMany(targetEntity = Action.class)
    @JoinTable(name = "select_action",
            joinColumns = @JoinColumn(name = "student_id",referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "action_id",referencedColumnName = "id"))
    private List<Action> actionList;

    //学生到考勤多对一关系,学生被动
    @JsonIgnoreProperties(value = "studentList")
    @ManyToOne(targetEntity = Attendance.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "attendance_id",referencedColumnName = "id")
    private Attendance attendance;

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public Grade getGrade() {
        return grade;
    }

    public void setGrade(Grade grade) {
        this.grade = grade;
    }

    public Dormitory getDormitory() {
        return dormitory;
    }

    public void setDormitory(Dormitory dormitory) {
        this.dormitory = dormitory;
    }

    public List<Course> getCourseList() {
        return courseList;
    }

    public void setCourseList(List<Course> courseList) {
        this.courseList = courseList;
    }

    public List<Score> getScoreList() {
        return scoreList;
    }

    public void setScoreList(List<Score> scoreList) {
        this.scoreList = scoreList;
    }

    public List<Action> getActionList() {
        return actionList;
    }

    public void setActionList(List<Action> actionList) {
        this.actionList = actionList;
    }

    public Attendance getAttendance() {
        return attendance;
    }

    public void setAttendance(Attendance attendance) {
        this.attendance = attendance;
    }

    @Override
    public String toString() {
        return "Student{" +
                "number='" + number + '\'' +
                ", sex='" + sex + '\'' +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", telephone='" + telephone + '\'' +
                '}';
    }
}
